home *** CD-ROM | disk | FTP | other *** search
/ Programming Windows 95 / Programming Windows 95.iso / code / CHAP02 / HELLOWIN.C next >
Encoding:
C/C++ Source or Header  |  1996-01-01  |  2.9 KB  |  86 lines

  1. /*------------------------------------------------------------
  2.    HELLOWIN.C -- Displays "Hello, Windows 95!" in client area
  3.                  (c) Charles Petzold, 1996
  4.   ------------------------------------------------------------*/
  5.  
  6. #include <windows.h>
  7.  
  8. LRESULT CALLBACK WndProc (HWND, UINT, WPARAM, LPARAM) ;
  9.  
  10. int WINAPI WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance,
  11.                     PSTR szCmdLine, int iCmdShow)
  12.      {
  13.      static char szAppName[] = "HelloWin" ;
  14.      HWND        hwnd ;
  15.      MSG         msg ;
  16.      WNDCLASSEX  wndclass ;
  17.  
  18.      wndclass.cbSize        = sizeof (wndclass) ;
  19.      wndclass.style         = CS_HREDRAW | CS_VREDRAW ;
  20.      wndclass.lpfnWndProc   = WndProc ;
  21.      wndclass.cbClsExtra    = 0 ;
  22.      wndclass.cbWndExtra    = 0 ;
  23.      wndclass.hInstance     = hInstance ;
  24.      wndclass.hIcon         = LoadIcon (NULL, IDI_APPLICATION) ;
  25.      wndclass.hCursor       = LoadCursor (NULL, IDC_ARROW) ;
  26.      wndclass.hbrBackground = (HBRUSH) GetStockObject (WHITE_BRUSH) ;
  27.      wndclass.lpszMenuName  = NULL ;
  28.      wndclass.lpszClassName = szAppName ;
  29.      wndclass.hIconSm       = LoadIcon (NULL, IDI_APPLICATION) ;
  30.  
  31.      RegisterClassEx (&wndclass) ;
  32.  
  33.      hwnd = CreateWindow (szAppName,         // window class name
  34.                     "The Hello Program",     // window caption
  35.                     WS_OVERLAPPEDWINDOW,     // window style
  36.                     CW_USEDEFAULT,           // initial x position
  37.                     CW_USEDEFAULT,           // initial y position
  38.                     CW_USEDEFAULT,           // initial x size
  39.                     CW_USEDEFAULT,           // initial y size
  40.                     NULL,                    // parent window handle
  41.                     NULL,                    // window menu handle
  42.                     hInstance,               // program instance handle
  43.                     NULL) ;                     // creation parameters
  44.  
  45.      ShowWindow (hwnd, iCmdShow) ;
  46.      UpdateWindow (hwnd) ;
  47.  
  48.      while (GetMessage (&msg, NULL, 0, 0))
  49.           {
  50.           TranslateMessage (&msg) ;
  51.           DispatchMessage (&msg) ;
  52.           }
  53.      return msg.wParam ;
  54.      }
  55.  
  56. LRESULT CALLBACK WndProc (HWND hwnd, UINT iMsg, WPARAM wParam, LPARAM lParam)
  57.      {
  58.      HDC         hdc ;
  59.      PAINTSTRUCT ps ;
  60.      RECT        rect ;
  61.  
  62.      switch (iMsg)
  63.           {
  64.           case WM_CREATE :
  65.                PlaySound ("hellowin.wav", NULL, SND_FILENAME | SND_ASYNC) ;
  66.                return 0 ;
  67.  
  68.           case WM_PAINT :
  69.                hdc = BeginPaint (hwnd, &ps) ;
  70.  
  71.                GetClientRect (hwnd, &rect) ;
  72.  
  73.                DrawText (hdc, "Hello, Windows 95!", -1, &rect,
  74.                          DT_SINGLELINE | DT_CENTER | DT_VCENTER) ;
  75.  
  76.                EndPaint (hwnd, &ps) ;
  77.                return 0 ;
  78.  
  79.           case WM_DESTROY :
  80.                PostQuitMessage (0) ;
  81.                return 0 ;
  82.           }
  83.  
  84.      return DefWindowProc (hwnd, iMsg, wParam, lParam) ;
  85.      }
  86.